package org.ruiyichen.guizhou.agr.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import org.ruiyichen.guizhou.agr.R;
import org.ruiyichen.guizhou.agr.imp.IIrrigatedDeviceFilter;
import org.ruiyichen.guizhou.agr.ui.listener.OnRecyclerItemClick;
import org.ruiyichen.guizhou.agr.utils.ListUtil;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;


/**
 * 类描述：家庭成员
 *
 * @version 1.0
 */
public class DefaultDeviceRecyclerAdapter extends RecyclerView.Adapter<DefaultDeviceRecyclerAdapter.BViewHolder> {

    private List<? extends IIrrigatedDeviceFilter> mDatas;
    private Context mContext;
    private LayoutInflater inflater;

    private OnRecyclerItemClick onRecyclerItemClick;


    public DefaultDeviceRecyclerAdapter(Context context) {
        this.mContext = context;
        inflater = LayoutInflater.from(mContext);
    }

    public void setmDatas(List<? extends IIrrigatedDeviceFilter> mDatas) {
        this.mDatas = mDatas;
        notifyDataSetChanged();
    }

    public void setOnRecyclerItemClick(OnRecyclerItemClick onRecyclerItemClick) {
        this.onRecyclerItemClick = onRecyclerItemClick;
    }

    //填充onCreateViewHolder方法返回的holder中的控件
    @Override
    public void onBindViewHolder(BViewHolder holder, final int position) {
        holder.tvIrrigatedDeviceListDesc.setText(mDatas.get(position).getIIrrigatedDeviceDesc());
        holder.ivIrrigatedDeviceSelect.setSelected(mDatas.get(position).isISelected());
    }

    //重写onCreateViewHolder方法，返回一个自定义的ViewHolder
    @Override
    public BViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.df_item_irrigated_device, parent, false);
        BViewHolder holder = new BViewHolder(view);
        return holder;
    }

    @Override
    public int getItemCount() {
        if (mDatas == null) return 0;
        return mDatas.size();
    }


    /**
     * 协办员
     */
    class BViewHolder extends RecyclerView.ViewHolder {

        ImageView
                ivIrrigatedDeviceSelect;

        TextView
                tvIrrigatedDeviceListDesc;

        public BViewHolder(final View view) {
            super(view);
            ivIrrigatedDeviceSelect = view.findViewById(R.id.iv_irrigated_device_select);
            ivIrrigatedDeviceSelect.setVisibility(View.GONE);
            tvIrrigatedDeviceListDesc = view.findViewById(R.id.tv_irrigated_device_list_desc);
        }
    }
}
